package com.example.medicinebox.model

import android.annotation.SuppressLint

data class ClockAtomic(val hour: Int, val minute: Int, val second: Int, val medicineBox: List<Boolean>) {
    @SuppressLint("DefaultLocale")
    fun getTimeString(): String {
        return String.format("%02d:%02d:%02d", hour, minute, second)
    }

    fun getMedicines(): String {
        val medicines = StringBuilder()
        var index = 1
        var isFlag = false

        medicineBox.forEach { isChecked ->

            if (isChecked) {
                if (isFlag) {
                    medicines.append(",")
                }
                medicines.append(index)
                isFlag = true
            }
            index += 1
        }

        return medicines.toString()
    }

    fun getMedicinesWithoutSplit(): String {
        val medicines = StringBuilder()
        var index = 1

        medicineBox.forEach { isChecked ->
            if (isChecked) {
                medicines.append(index)
            }
            index += 1
        }

        if (medicines.isEmpty()) {
            return "0"
        }

        return medicines.toString()
    }
}